/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of UHM (Unassembled HyperMatrix) sparse direct solver.
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#include "uhm.hxx"

#include "uhm/interf/wsmp.hxx"
#include "uhm/wrapper/wsmp_fort.hxx"

//----------------------------------------------------------------------
// FORTRAN INTERFACE
//----------------------------------------------------------------------

// ** WSMP
//----------------------------------------------------------------------
void UHM_C2F(uhm_mesh_export_matrix_wsmp)     ( uhm_fort_p   *mesh,
                                                uhm_fort_p   *wsmp,
                                                uhm_fort_int *n_rhs ) {
  uhm::Mesh m = (uhm::Mesh)( *mesh );
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  m->export_matrix(w, *n_rhs);
}

void UHM_C2F(uhm_wsmp_create)                 ( uhm_fort_p   *wsmp,
                                                uhm_fort_int *datatype ) {
  uhm::interf::WSMP w = new uhm::interf::WSMP_( *datatype );
  *wsmp = (uhm_fort_p)w;
}

void UHM_C2F(uhm_wsmp_delete)                 ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  delete w;
}

void UHM_C2F(uhm_wsmp_set_show_n_rhs)         ( uhm_fort_p   *wsmp,
                                                uhm_fort_int *show_n_rhs) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->set_show_n_rhs(*show_n_rhs);
}

void UHM_C2F(uhm_wsmp_set_iparm)              ( uhm_fort_p   *wsmp,
                                                uhm_fort_int *idx,
                                                uhm_fort_int *val ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->set_iparm( *idx, *val );
}

void UHM_C2F(uhm_wsmp_set_dparm)              ( uhm_fort_p   *wsmp,
                                                uhm_fort_int *idx,
                                                uhm_fort_double *val ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->set_dparm( *idx, *val );
}

void UHM_C2F(uhm_wsmp_init)                   ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->init();
}

void UHM_C2F(uhm_wsmp_analyze)                ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->analyze();
}

void UHM_C2F(uhm_wsmp_decompose)              ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->decompose();
}

void UHM_C2F(uhm_wsmp_solve)                  ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->solve();
}

void UHM_C2F(uhm_wsmp_refine)                 ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->refine();
}

void UHM_C2F(uhm_wsmp_export_matrix_uhm)      ( uhm_fort_p   *wsmp,
                                                uhm_fort_p   *mesh ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  uhm::Mesh m = (uhm::Mesh)( *mesh );
  w->export_matrix(m);
}

void UHM_C2F(uhm_wsmp_finalize)               ( uhm_fort_p   *wsmp ) {
  uhm::interf::WSMP w = (uhm::interf::WSMP)( *wsmp );
  w->finalize();
}
